Skip to main content
Version: 1.10.x

Remote User

Remote user management for creating and managing users in the sandbox.

Usage Examples​

import asyncio
from rock.sdk.sandbox.config import SandboxConfig
from rock.sdk.sandbox.client import Sandbox

from rock.actions import Action, CreateBashSessionRequest, Observation


async def test_remote_user():
config = SandboxConfig(
image='hub.docker.alibaba-inc.com/chatos/python:3.11',
xrl_authorization='xxx',
cluster='nt-c'
)
sandbox = Sandbox(config)
await sandbox.start()

await sandbox.remote_user.create_remote_user('rock')
assert await sandbox.remote_user.is_user_exist('rock')
print('test remote user success')

async def test_create_session_with_remote_user():
config = SandboxConfig(
image='hub.docker.alibaba-inc.com/chatos/python:3.11',
xrl_authorization='xxx',
cluster='nt-c'
)
sandbox = Sandbox(config)
await sandbox.start()

await sandbox.remote_user.create_remote_user('rock')
assert await sandbox.remote_user.is_user_exist('rock')

await sandbox.create_session(CreateBashSessionRequest(remote_user="rock", session="bash"))

observation: Observation = await sandbox.run_in_session(
action=Action(session="bash", command="whoami")
)
print(observation)
assert observation.output.strip() == "rock"
print('test create session with remote user success')

if __name__ == '__main__':
asyncio.run(test_remote_user())
asyncio.run(test_create_session_with_remote_user())

API​

create_remote_user(username)​

Create a remote user.

await sandbox.remote_user.create_remote_user('username')

is_user_exist(username)​

Check if a user exists.

exists = await sandbox.remote_user.is_user_exist('username')